package com.servlet_demo;

import service.ActorService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AddServlet extends HttpServlet {

    private ActorService actorService = new ActorService();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /**
         * post方式下表单提交中文会乱码需要设置字符集
         * get方式不需要(Tomcat8之后)
         */
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");
        String sex = request.getParameter("sex");
        String phone = request.getParameter("phone");
        boolean add = actorService.add(name, sex, phone);
        if (add) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
    }


}
